package vip.liux.backend.adapter.controllers.notification;

import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vip.liux.application.dots.ListResultDto;
import vip.liux.backend.application.service.messaging.CreateNotificationPolicyDto;
import vip.liux.backend.application.service.messaging.MessageTemplateService;
import vip.liux.contracts.infrastructure.messaging.MessageTemplateValueObj;

@RestController
@RequestMapping("/api/notification-policies")
public class NotificationTemplateController {

    @Autowired
    private MessageTemplateService notificationMessageService;

    /**
     * 创建通知模板
     */
    @PostMapping
    public ResponseEntity<MessageTemplateValueObj> create(@RequestBody @Valid CreateNotificationPolicyDto dto) {
        return ResponseEntity.ok(notificationMessageService.create(dto));
    }

    /**
     * 查询通知模板列表
     */
    @GetMapping
    public ResponseEntity<ListResultDto<MessageTemplateValueObj>> list(@RequestParam(required = false) String name) {
        return ResponseEntity.ok(notificationMessageService.list(name));
    }

    /**
     * 修改通知模板状态
     */
    @PutMapping("/{code}/status")
    public ResponseEntity<Void> changeStatus(@PathVariable String code, @RequestParam boolean enable) {
        notificationMessageService.changeStatus(code, enable);
        return ResponseEntity.noContent().build();
    }
}